package com.ruoyi.loan.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loan.domain.TbPeriods;
import com.ruoyi.loan.service.ITbPeriodsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 期数Controller
 * 
 * @author jy
 * @date 2023-01-14
 */
@RestController
@RequestMapping("/periods")
public class TbPeriodsController extends BaseController
{
    @Autowired
    private ITbPeriodsService tbPeriodsService;

    /**
     * 查询期数列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbPeriods tbPeriods)
    {
        startPage();
        List<TbPeriods> list = tbPeriodsService.selectTbPeriodsList(tbPeriods);
        return getDataTable(list);
    }

    /**
     * 导出期数列表
     */
    @Log(title = "期数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPeriods tbPeriods)
    {
        List<TbPeriods> list = tbPeriodsService.selectTbPeriodsList(tbPeriods);
        ExcelUtil<TbPeriods> util = new ExcelUtil<TbPeriods>(TbPeriods.class);
        util.exportExcel(response, list, "期数数据");
    }

    /**
     * 获取期数详细信息
     */
    @GetMapping(value = "/getPeriods/{periodsId}")
    public AjaxResult getInfo(@PathVariable("periodsId") Long periodsId)
    {
        return success(tbPeriodsService.selectTbPeriodsByPeriodsId(periodsId));
    }

    /**
     * 新增期数
     */
    @Log(title = "期数", businessType = BusinessType.INSERT)
    @PostMapping("/addPeriods")
    public AjaxResult add(@RequestBody TbPeriods tbPeriods)
    {
        return toAjax(tbPeriodsService.insertTbPeriods(tbPeriods));
    }

    /**
     * 修改期数
     */
    @RequiresPermissions("system:periods:edit")
    @Log(title = "期数", businessType = BusinessType.UPDATE)
    @PutMapping("/updatePeriods")
    public AjaxResult edit(@RequestBody TbPeriods tbPeriods)
    {
        return toAjax(tbPeriodsService.updateTbPeriods(tbPeriods));
    }

    /**
     * 删除期数
     */
    @RequiresPermissions("system:periods:remove")
    @Log(title = "期数", businessType = BusinessType.DELETE)
	@DeleteMapping("/delPeriods/{periodsIds}")
    public AjaxResult remove(@PathVariable Long[] periodsIds)
    {
        return toAjax(tbPeriodsService.deleteTbPeriodsByPeriodsIds(periodsIds));
    }
}
